# Maintainer: Martell Malone <Martell Malone at g mail dot com>

_realname=ninja
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.10.0
pkgrel=1
pkgdesc="Ninja is a small build system with a focus on speed (mingw-w64)"
arch=('any')
url="https://ninja-build.org"
license=('Apache')
depends=()
options=('strip' 'staticlibs')
makedepends=("re2c" "${MINGW_PACKAGE_PREFIX}-python3")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/ninja-build/ninja/archive/v${pkgver}.tar.gz")
sha256sums=('3810318b08489435f8efc19c05525e80a993af5a55baa0dfeae0465a9d45f99f')

prepare () {
  cd ${srcdir}/ninja-${pkgver}
  #linking assumes windows cmd line but we are bash :)
  sed -i 's|cmd /c $ar cqs $out.tmp $in && move /Y $out.tmp $out|$ar crs $out $in|g' ${srcdir}/ninja-${pkgver}/configure.py
}

build() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  cd ${srcdir}/ninja-${pkgver}
  ${MINGW_PREFIX}/bin/python3 configure.py --bootstrap --platform mingw
}

package() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  mv "${srcdir}/ninja-${pkgver}/ninja.exe" "${pkgdir}${MINGW_PREFIX}"/bin/
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/lib
  mv "${srcdir}/ninja-${pkgver}/build/libninja.a" "${pkgdir}${MINGW_PREFIX}"/lib/
}
